package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.contract.pc.BrandFirmsSkuListValidRequestBean;
import com.homedo.odin.solution.contract.pc.SolutionHomedoListResp;
import com.homedo.odin.solution.service.bizservice.mng.MngBrandFirmsService;
import com.homedo.odin.solution.service.bizservice.pc.SkuBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhaoxudong
 * @date: 2018/4/4 13:38
 * @Description:
 */
@Api(description = "Sku", tags = {"Sku"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/sku")
public class SkuController extends BaseController<SkuBizService> {

    @Autowired
    private MngBrandFirmsService brandFirmsService;

    @ApiOperation(value = "PC_根据skuId查找方案列表(供平台调用)", notes = "PC_根据skuId查找方案列表(供平台调用)",
            response = SolutionHomedoListResp.class)
    @GetMapping("/{skuId}/solutions")
    public ResultData solutions(@ApiParam("商品skuId") @PathVariable("skuId") String skuId) {
        List<SolutionHomedoListResp> resp = baseService.solutions(skuId);
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "PC_获取品牌主关联的产品信息", httpMethod = "GET")
    @GetMapping("/brand_firms/{uid}")
    public ResultData getBrands(@Valid @ModelAttribute BrandFirmsSkuListValidRequestBean requestBean,
            BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultData.newInstance(new Meta(Meta.CODE_451.getCode(),
                    bindingResult.getFieldError().getDefaultMessage()));
        }

        return ResultData.newInstance(brandFirmsService.getBrands(requestBean));
    }
}
